#!/bin/bash

version=$(cat openstack-regionagent.spec |grep "^Version"|awk '{print $2}')
srcfile="openstack-regionagent-${version}.tar.gz"
specfile="openstack-regionagent.spec"

if [ $# -eq 0 ];then
  echo "Usage: $0 -ba|-bp"
  exit
fi
HOME=/tmp/`whoami`
builddir=${HOME}/rpmbuild
mkdir -p  $builddir/SOURCES $builddir/SPECS

if [ ! -f $srcfile ]; then
 echo "FATAL: $srcfile not found"
 exit 1
fi

cp $srcfile  ${builddir}/SOURCES/

cp *.patch ${builddir}/SOURCES/

cp ${specfile} ${builddir}/SPECS/
cd ${builddir}/SPECS && rpmbuild ${1} ${specfile}
